package com.yf.exam.job;

import com.alibaba.fastjson.JSON;
import com.yf.exam.modules.exam.dto.ExamApplyDTO;
import com.yf.exam.modules.exam.service.ExamApplyService;
import com.yf.job.service.JobService;
import lombok.extern.log4j.Log4j2;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 超时自动交卷任务
 * @author bool
 */
@Log4j2
@Component
public class ClearApplyJob implements Job {

    @Autowired
    private ExamApplyService examApplyService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {


        JobDetail detail = jobExecutionContext.getJobDetail();
        String name = detail.getKey().getName();
        String group = detail.getKey().getGroup();
        String data = String.valueOf(detail.getJobDataMap().get(JobService.TASK_DATA));

        log.info("++++++++++定时任务：消耗考试申请");
        log.info("++++++++++jobName:{}", name);
        log.info("++++++++++jobGroup:{}", group);
        log.info("++++++++++taskData:{}", data);

        // 消耗申请
        ExamApplyDTO dto = JSON.parseObject(data, ExamApplyDTO.class);
        examApplyService.useAudit(dto.getApplyUser(), dto.getExamId());

    }



}
